package string;

/**
 * StringBuilder演示
 */
public class StringBuilderDemo {
    public static void main(String[] args) {
        String str="好好学习java";
        StringBuilder builder=new StringBuilder(str);
        StringBuffer buffer=new StringBuffer(str);


        builder.append("，为了找个好工作");
        System.out.println(builder);

        builder.append(",为了兴趣");
        System.out.println(builder);

        builder.replace(9,18,"为了改变世界");
        System.out.println(builder);
        builder.replace(9,23,"为了改变世界");
        System.out.println(builder);

        builder.delete(0,8);
        System.out.println(builder);
        builder.insert(0,"活着");
        System.out.println(builder);

        builder.insert(3,"ggg");
        System.out.println(builder);






        /**
        //StringBuilder的创建方式：
        StringBuilder builder1=new StringBuilder();
        StringBuilder builder2=new StringBuilder("abc");

        //String和StringBuilder的互转：
        String s1="abc";
        StringBuilder builder3=new StringBuilder(s1);
        String s2=builder3.toString();

         */

    }
}
